import React, { Component } from 'react';

import Child1 from './Child1';
import Child2 from './Child2';
class Father extends Component {
    state = {
        flag: true
    }
    render() {
        return (
            <div>
                <button onClick={this.changeFn}>切换组件</button>
                {
                    this.state.flag ? <Child1></Child1> : <Child2 />
                }
            </div>
        );
    }
    // 修改flag 状态
    changeFn = () => {
        this.setState({
            flag: !this.state.flag
        })
    }

}

export default Father;
